//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class ColorChangeEffect : Effect
    {
        private ColorBase clrFrom;
        private ColorBase clrTo;
        private bool UseA;

        public bool UseAlpha
        {
            get { return UseA; }
            set { UseA = value; }
        }

        public ColorBase FromColor
        {
            get { return clrFrom; }
            set { clrFrom = value; }
        }

        public ColorBase ToColor
        {
            get { return clrTo; }
            set { clrTo = value; }
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("clrChange"))
            {
                UseA = c.GetOptionalBoolean("useA", true);
                using (ReadContext c2 = c.Read("clrFrom"))
                {
                    clrFrom = ColorBase.ReadColor(c2);
                }
                using (ReadContext c2 = c.Read("clrTo"))
                {
                    clrTo = ColorBase.ReadColor(c2);
                }
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("clrChange"))
            {
                c.SetOptionalBoolean("useA", UseA, true);
                using (WriteContext c2 = c.Write("clrFrom"))
                {
                    c2.WriteOptionalElement(clrFrom);
                }
                using (WriteContext c2 = c.Write("clrTo"))
                {
                    c2.WriteOptionalElement(clrTo);
                }
            }
        }
    }
}